home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / CT Explorer / Form1.cs < prev    next >
Text File  |  2005-05-08  |  5KB  |  231 lines

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using CsGL.OpenGL;
  8.  
  9. namespace SampleGUI
  10. {
  11.     /// <summary>
  12.     /// Summary description for Form1.
  13.     /// </summary>
  14.     public class Form1 : System.Windows.Forms.Form
  15.     {
  16.         /// <summary>
  17.         /// Required designer variable.
  18.         /// </summary>
  19.         /// 
  20.  
  21.         public MainForm orthoForm;
  22.         private System.ComponentModel.Container components = null;
  23.  
  24.         public Form1()
  25.         {
  26.             //
  27.             // Required for Windows Form Designer support
  28.             //
  29.             InitializeComponent();
  30.             orthoForm = new MainForm(this);
  31.             //this.MdiChildren = orthoForm;
  32.             //orthoForm.Show();
  33.  
  34.  
  35.             //
  36.             // TODO: Add any constructor code after InitializeComponent call
  37.             //
  38.         }
  39.  
  40.         /// <summary>
  41.         /// Clean up any resources being used.
  42.         /// </summary>
  43.         protected override void Dispose( bool disposing )
  44.         {
  45.             if( disposing )
  46.             {
  47.                 if (components != null) 
  48.                 {
  49.                     components.Dispose();
  50.                 }
  51.             }
  52.             base.Dispose( disposing );
  53.         }
  54.  
  55.         #region Windows Form Designer generated code
  56.         /// <summary>
  57.         /// Required method for Designer support - do not modify
  58.         /// the contents of this method with the code editor.
  59.         /// </summary>
  60.         private void InitializeComponent()
  61.         {
  62.             this.components = new System.ComponentModel.Container();
  63.             this.Size = new System.Drawing.Size(300,300);
  64.             this.Text = "Form1";
  65.         }
  66.         #endregion
  67.  
  68.         /// <summary>
  69.         /// The main entry point for the application.
  70.         /// </summary>
  71.         [STAThread]
  72.         static void Main() 
  73.         {
  74.             Application.Run(new Form1());
  75.         }
  76.     }
  77.  
  78.     public class MainForm : System.Windows.Forms.Form
  79.     {
  80.         /// <summary>
  81.         /// Required designer variable.
  82.         /// </summary>
  83.         /// 
  84.         View view1 = new View();
  85.         View view2 = new View();
  86.         View view3 = new View();
  87.         private System.Windows.Forms.Panel panel1;
  88.         private System.Windows.Forms.Panel panel2;
  89.         private System.Windows.Forms.Panel panel3;
  90.  
  91.         private System.ComponentModel.Container components = null;
  92.  
  93.         public MainForm(Form parentForm)
  94.         {
  95.             //
  96.             // Required for Windows Form Designer support
  97.             //
  98.             //InitializeComponent();
  99.  
  100.             //set the form to the parent form
  101.             this.Parent = parentForm;
  102.             
  103.             //set the size of the window
  104.             //this.SetClientSizeCore(800,300);
  105.  
  106.             //place the views in the panels
  107.             panel1 = new System.Windows.Forms.Panel();
  108.             this.panel1.Controls.AddRange(
  109.                 new System.Windows.Forms.Control[] { this.view1 });
  110.  
  111.             this.panel2 = new System.Windows.Forms.Panel();
  112.             this.panel2.Controls.AddRange(
  113.                 new System.Windows.Forms.Control[] { this.view2 });
  114.  
  115.             this.panel3 = new System.Windows.Forms.Panel();
  116.             this.panel3.Controls.AddRange(
  117.                 new System.Windows.Forms.Control[] { this.view3 });
  118.             
  119.             //add panel to form
  120.             this.Controls.AddRange(
  121.                 new System.Windows.Forms.Control[] {this.panel1,
  122.                                                        this.panel2,
  123.                                                        this.panel3
  124.                                                    });
  125.  
  126.  
  127.             int cx = this.ClientSize.Width;
  128.             int cy = this.ClientSize.Height;
  129.  
  130.             //set position of panel and view docking and color
  131.             panel1.SetBounds(0,0,(int)(cx/3.0),cy);
  132.             panel1.BorderStyle = BorderStyle.Fixed3D;
  133.             view1.Dock = DockStyle.Fill;
  134.             view1.Color[0] = 1;
  135.             view1.Color[1] = 0;
  136.             view1.Color[2] = 0;
  137.  
  138.             panel2.SetBounds((int)(cx/3.0),0,(int)(cx/3.0),cy);
  139.             panel2.BorderStyle = BorderStyle.Fixed3D;
  140.             view2.Dock = DockStyle.Fill;
  141.             view2.Color[0] = 0;
  142.             view2.Color[1] = 1;
  143.             view2.Color[2] = 0;
  144.  
  145.             panel3.SetBounds((int)(2*cx/3.0),0,(int)(cx/3.0),cy);
  146.             panel3.BorderStyle = BorderStyle.Fixed3D;
  147.             view3.Dock = DockStyle.Fill;
  148.             view3.Color[0] = 0;
  149.             view3.Color[1] = 0;
  150.             view3.Color[2] = 1;
  151.  
  152.             this.Resize += new EventHandler(form_Resize);
  153.         }
  154.  
  155.         void form_Resize(object sender, EventArgs e)
  156.         {
  157.             int cx = this.ClientSize.Width;
  158.             int cy = this.ClientSize.Height;
  159.  
  160.             //set position of panels
  161.             panel1.SetBounds(0,0,(int)(cx/3.0),cy);
  162.             panel2.SetBounds((int)(cx/3.0),0,(int)(cx/3.0),cy);
  163.             panel3.SetBounds((int)(2*cx/3.0),0,(int)(cx/3.0),cy);
  164.  
  165.         }
  166.  
  167.  
  168.         /// <summary>
  169.         /// Clean up any resources being used.
  170.         /// </summary>
  171.         protected override void Dispose( bool disposing )
  172.         {
  173.             if( disposing )
  174.             {
  175.                 if (components != null) 
  176.                 {
  177.                     components.Dispose();
  178.                 }
  179.             }
  180.             base.Dispose( disposing );
  181.         }
  182.     }
  183.  
  184.     class View : OpenGLControl
  185.     {
  186.         public float[] Color = new float[3];
  187.     
  188.         public View()
  189.         {
  190.             //default color to red
  191.             Color[0] = 1;
  192.             Color[1] = 0;
  193.             Color[2] = 0;
  194.         }
  195.  
  196.         public override void glDraw()
  197.         {
  198.             GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear Screen And Depth Buffer
  199.             GL.glShadeModel( GL.GL_SMOOTH );
  200.  
  201.             CsGL.OpenGL.GLUquadric q = GL.gluNewQuadric();
  202.             int radius;
  203.             radius = 1;
  204.  
  205.             GL.gluQuadricDrawStyle(q,GL.GLU_LINE);
  206.             GL.glColor3fv(Color);
  207.             GL.gluSphere(q, radius, 20, 20);
  208.  
  209.             GL.glFlush();
  210.         }
  211.         protected override void InitGLContext()
  212.         {        
  213.             GL.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  214.             GL.glEnable( GL.GL_DEPTH_TEST);
  215.         }
  216.         protected override void OnSizeChanged(EventArgs e)
  217.         {
  218.             base.OnSizeChanged(e);
  219.             GL.glMatrixMode(GL.GL_PROJECTION);
  220.             GL.glLoadIdentity();
  221.             //GL.glOrtho( -20,20, -20,20, 0,1000);
  222.             GL.gluPerspective(90,1, 0.1,1000);
  223.  
  224.         
  225.             GL.glMatrixMode(GL.GL_MODELVIEW );
  226.             GL.glLoadIdentity();
  227.             GL.gluLookAt(0,0,3, 0,0,0, 0,1,0);
  228.         }
  229.     }
  230. }
  231.